<template lang="pug">
div
  create-modal(
    :show.sync="show",
    :type="type",
  )
  .ui.top.fixed.menu
    .ui.container
      //- a.item(v-link="{ name: 'index'}") PQ
      .ui.dropdown.item.link(v-link="{ name: 'orders', activeClass: 'active-item' }")
        | 订单
        //- i.dropdown.icon
        .menu
          a.item(v-link="{ name: 'orders', query: { group: 1 }}") 进行中订单
          a.item(v-link="{ name: 'orders', query: { group: 2 }}") 已存档订单
          a.item(v-link="{ name: 'orders', query: { group: 1, state: 4 }}") 售后订单
          //- 售后订单->进行中的售后订单
          .divider
          a.item.normal(v-link="{ path: '', append: true }", @click="createOrderFn")
            i.icon.plus.no-margin.no-padding
            | 创建订单
          //- a.item.normal(v-link="{ path: '', append: true }", @click="createOrderFn('optometry_try')")
          //-   i.icon.plus.no-margin.no-padding
          //-   | 创建验光试戴订单
          //- a.item.normal(v-link="{ path: '', append: true }", @click="createOrderFn('optometry')")
          //-   i.icon.plus.no-margin.no-padding
          //-   | 创建验光订单
          //- a.item.normal(v-link="{ path: '', append: true }", @click="createOrderFn('buy')")
          //-   i.icon.plus.no-margin.no-padding
          //-   | 创建购买订单
      .ui.dropdown.item.link(v-link="{ name: 'reports', activeClass: 'active-item' }")
        | 验光报告
        .menu
          a.item.normal(v-link="{ path: '', append: true }", @click="createReportFn")
            i.icon.plus.no-margin.no-padding
            | 增加验光报告
      a.item(v-link="{ name: 'msgs', activeClass: 'active' }") 消息
      .ui.dropdown.item.link(v-link="{ name: 'users', activeClass: 'active-item' }")
        | 用户
        //- .menu
        //-   a.item.normal(v-link="{ path: '', append: true }")
        //-     i.icon.plus.no-margin.no-padding
        //-     | 创建用户
      .ui.dropdown.item.link(v-link="{ name: 'products', activeClass: 'active-item' }")
        | 产品
        .menu
          a.item.normal(v-link="{ path: '', append: true }", @click="createProductFn")
            i.icon.plus.no-margin.no-padding
            | 增加产品
      .ui.dropdown.item.link(v-link="{ name: 'optometrists', activeClass: 'active-item' }")
        | 验光师
        .menu
          a.item.normal(v-link="{ path: '', append: true }", @click="createOptometristFn")
            i.icon.plus.no-margin.no-padding
            | 增加验光师
      .ui.dropdown.item.link(v-link="{ name: 'coupons', activeClass: 'active-item' }")
        | 优惠券
        .menu
          a.item.normal(v-link="{ path: '', append: true }", @click="createCouponFn")
            i.icon.plus.no-margin.no-padding
            | 发送优惠券给用户
          a.item.normal(v-link="{ path: '/coupons/list', append:true }")
            i.icon.plus.no-margin.no-padding
            | 批量优惠券列表
      a.item(v-link="{ name: 'settings', activeClass: 'active' }") 设置
      a.item(v-link="{ name: 'articles', activeClass: 'active-item' }") PQ文章
      a.item(v-link="{ path: '/articles/new'}",target="_blank") 增加PQ文章  
      //- .right.item(style="margin-left: 0 !important;") {{time}}
      .right.menu
        slot(name="search")
        .ui.dropdown.item.link
          //- i.icon.user
          | {{name}}&nbsp;
          i.dropdown.icon.no-margin.no-padding
          .menu
            .item(@click="logOut") 登出
</template>

<script>
import { logOut, createCoupon, createReport, createProduct, createOrder, createOptometrist } from '../../vuex/action'
import CreateModal from '../../modules/modal/create'

export default {
  name: 'nav',
  components: {
    CreateModal,
  },
  vuex: {
    getters: {
      name: ({ user }) => user.me.name,
      type: ({ user }) => user.me.type,
    },
    actions: {
      logOut,
      createProduct,
      createOptometrist,
      createOrder,
      createReport,
    }
  },
  methods: {
    // getTime () {
    //   moment.locale('zh-cn')
    //   return moment().format('YYYY-M-D ddd HH:mm')
    // },
    createOptometristFn() {
      catchError(async () => {
        const now = moment().unix()
        await this.createOptometrist({
          name: `name_${now}`,
          phone: `${now}`,
          gender: 'male',
        })
      }, '创建成功')
    },
    createReportFn() {
      this.type = 'report'
      this.show = true
    },
    createOrderFn() {
      this.type = 'order'
      this.show = true
    },
    createCouponFn(){
      this.type = 'coupon'
      this.show = true
    },
    // createOrderFn(category) {
    //   catchError(async () => {
    //     await this.createOrder({
    //       category,
    //     })
    //   }, '创建成功')
    // },
    createProductFn () {
      catchError(async () => {
        const now = moment().unix()
        await this.createProduct({
          name: `name_${now}`,
          url: `url_${now}`,
          sub_products: [
            {
              sku_name: `sku_name_${now}`,
              name: '黑',
              stock: 0,
              index: 0,
              url: `sku_url_${now}`,
              thumbnail: {
                large: null,
                dot: null,
              },
              status: 'down',
              description: [{
                type: 'simple',
                photo: null,
                text: null,
              }],
            }
          ]
        })
      }, '创建成功')
    },
  },
  data () {
    return {
      // time: this.getTime(),
      show: false,
      type: null,
    }
  },
  created () {
    // setInterval(() => {
    //   this.time = this.getTime()
    // }, 60*1000)
  },
  ready () {
    $(this.$el).find('.dropdown').dropdown({
      on: 'hover'
    })
  },
}
</script>

<style lang="sass" scoped>
</style>
